/**
 * @author 铭
 * @TODO 10/1/2024
 */
package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entitys.TbHospital;
import com.woniuxy.entitys.TbHospitalManager;
import com.woniuxy.service.HospitalInfoService;
import com.woniuxy.utils.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class HospitalInfoController {
    @Autowired
    private HospitalInfoService hospitalInfoService;

    @PostMapping("hospital/search")
    public ResultVO search(@RequestBody Map<String, Object> map){
        List list = new ArrayList();
        Integer pageNum = (Integer) map.get("pageNum");
        list = (List<String>) map.get("dateArr");
        String input = (String) map.get("input");

        PageInfo search = hospitalInfoService.search(pageNum, list, input);
        return search!=null?ResultVO.success("",search):ResultVO.failure();
    }
    @PutMapping("hospital/refDel/{id}" )
    public ResultVO refDel(@PathVariable Integer id){
        int i = hospitalInfoService.refDel(id);
        return i>0?ResultVO.success(""):ResultVO.failure();
    }
    @GetMapping("hospital/selMans")
    public ResultVO selMans(){
        List<TbHospitalManager> managers = hospitalInfoService.selMans();
        return managers!=null?ResultVO.success("",managers):ResultVO.failure();
    }
    @PostMapping("hospital/addSave")
    public ResultVO addSave(@RequestBody TbHospital hospital){
        System.out.println(hospital);
        int i = hospitalInfoService.addHos(hospital);
        return i>0?ResultVO.success(""):ResultVO.failure();
    }
    @PutMapping("hospital/updSave")
    public ResultVO saveUpd(@RequestBody TbHospital hospital){
        int i = hospitalInfoService.saveUpd(hospital);
        return i>0?ResultVO.success(""):ResultVO.failure();
    }
}
